package com.shenhonghui.photo;

import com.shenhonghui.photo.slice.CameraAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.event.notification.NotificationRequest;
import ohos.rpc.IRemoteObject;
import ohos.rpc.RemoteException;

public class ServiceAbility extends Ability {
    private final int CAPTURE = 202;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        NotificationRequest.NotificationNormalContent content;
        NotificationRequest request = new NotificationRequest(1006);
        content = new NotificationRequest.NotificationNormalContent();
        content.setTitle("").setText("正在使用后台通信服务");
        NotificationRequest.NotificationContent notificationContent = new NotificationRequest.NotificationContent(content);
        request.setContent(notificationContent);
        keepBackgroundRunning(1006,request);
    }
    
    @Override
    public void onBackground() {
        super.onBackground();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    protected void onCommand(Intent intent, boolean restart, int startId) {
        super.onCommand(intent, restart, startId);
    }

    @Override
    protected IRemoteObject onConnect(Intent intent) {
        super.onConnect(intent);
        return new PictureInterface("Picture").asObject();
    }

    @Override
    protected void onDisconnect(Intent intent) {
        super.onDisconnect(intent);
    }

    class PictureInterface extends ServiceIdlInterfaceStub {

        public PictureInterface(String descriptor) {
            super(descriptor);
        }

        @Override
        public void capture() throws RemoteException {
            CameraAbilitySlice.getHandler().sendEvent(CAPTURE);
        }
    }
}

